<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 商品列表
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="goodsData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column prop="Goods_id" label="商品编号" width="100" align="center"></el-table-column>
                <el-table-column prop="Goods_name" label="商品名称"></el-table-column>
                <el-table-column prop="Gc_info" label="商品类别"></el-table-column>
                <el-table-column prop="Goods_price" label="价格"></el-table-column>
                <el-table-column prop="Goods_number" label="商品数量"></el-table-column>
                <el-table-column prop="Factory_name" label="厂家信息"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template #default="scope">
                        <el-button
                            type="primary"
                            @click="handlebuyGoods(scope.row)"
                        >购买</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="购买" v-model="buyVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="顾客ID">
                    <el-input v-model="orderData.Consumer_id"></el-input>
                </el-form-item>
                <el-form-item label="运输要求">
                    <el-input v-model="orderData.Trans_request"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="buyVisible = false">取 消</el-button>
                    <el-button type="primary" @click="buyGoods">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
    import {fetchgoodsData} from "../api/index";
    import {fetchBuyGoods} from "../api/index";
export default {
    name: "goodsData",
    data() {
        return {
			goodsData: [],

            orderData: {},
            query:{},
            multipleSelection: [],
            delList: [],
            buyVisible: false,
            pageTotal: 0,

            idx: -1,
            id: -1
        };
    },
    created() {
		this.getData()
    },
    methods: {

		getData(){
			fetchgoodsData().then(res =>{console.info(res)
                this.goodsData=res.data.value
			})
		},


        // 购买操作
        handlebuyGoods(row){
            this.orderData = row;
            this.buyVisible = true;
        },
        // 购买成功
        buyGoods() {
            this.buyVisible = false;
            this.$message.success(`下单成功`);
            fetchBuyGoods(this.orderData).then(res =>{console.info(res)
                console.log(this.orderData)
            })
        },
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
